//
//  HYThemeCell.m
//  _normal
//
//  Created by Ezra on 16/6/6.
//  Copyright © 2016年 Ezra. All rights reserved.
//

#import "HYThemeCell.h"
#import "HYTopThemeView.h"
#import "HYThemeViewModel.h"
#import "HYThemePictureView.h"
#import "HYThemeItem.h"
#import "HYVideoThemeView.h"
#import "HYVoiceThemeView.h"
#import "HYHotCommentView.h"
#import "HYBottomView.h"

@interface HYThemeCell()

@property (nonatomic, weak) HYTopThemeView *themeView;
@property (nonatomic, weak) HYThemePictureView *picView;
@property (nonatomic, weak) HYVideoThemeView *videoView;
@property (nonatomic, weak) HYVoiceThemeView *voiceView;
@property (nonatomic, weak) HYHotCommentView *hotView;
@property (nonatomic, weak) HYBottomView *bottomView;

@end

@implementation HYThemeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setFrame:(CGRect)frame
{
    
    frame.origin.y += 10;
    frame.size.height -= 10;
    
    [super setFrame:frame];
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //顶部的view
        HYTopThemeView *themeView = [HYTopThemeView viewForXib];
        [self.contentView addSubview:themeView];
        self.themeView = themeView;
        
        //中间的view
        HYThemePictureView *picView = [HYThemePictureView viewForXib];
        [self.contentView addSubview:picView];
        self.picView = picView;
        
        //视频的View
        HYVideoThemeView *videoView = [HYVideoThemeView viewForXib];
        [self.contentView addSubview:videoView];
        self.videoView = videoView;
        
        //音频的View
        HYVoiceThemeView *voiceView = [HYVoiceThemeView viewForXib];
        [self.contentView addSubview:voiceView];
        self.voiceView = voiceView;
        
        //热门评论的View
        HYHotCommentView *hotView = [HYHotCommentView viewForXib];
        [self.contentView addSubview:hotView];
        self.hotView = hotView;
        
        //底部的View
        HYBottomView *bottomView = [HYBottomView viewForXib];
        [self.contentView addSubview:bottomView];
        self.bottomView = bottomView;
        
    }
    return self;
}

-(void)setVm:(HYThemeViewModel *)vm
{
    _vm = vm;
    
    //顶部view
    self.themeView.item = vm.item;
    self.themeView.frame = vm.topViewFrame;
    
    
    //中部view
    if ([vm.item.filetype  isEqual: @"txt"]) {
        
        self.picView.hidden = NO;
        self.videoView.hidden = YES;
        self.voiceView.hidden = YES;
        
        self.picView.item = vm.item;
        self.picView.frame = vm.middleViewFrame;
        
        
    }else if ([vm.item.filetype  isEqual: @"video"]){
        
        self.picView.hidden = YES;
        self.voiceView.hidden = YES;
        self.videoView.hidden = NO;
        
        self.videoView.item = vm.item;
        self.videoView.frame = vm.middleViewFrame;
        
    }else if ([vm.item.filetype isEqual: @"music"]){
        
        self.picView.hidden = YES;
        self.videoView.hidden = YES;
        self.voiceView.hidden = NO;
        
        self.voiceView.item = vm.item;
        self.voiceView.frame = vm.middleViewFrame;
        
    }
//    else if (vm.item.filetype == HYThemeTypeText){
//
//        self.voiceView.hidden = YES;
//        self.videoView.hidden = YES;
//        self.picView.hidden = YES;
//    }
    
    /** 1.搭建最热评论view 2.解析Plist,在模型中定义最热评论数据 3.给最热评论的view传递模型 4.在视图模型中计算最热评论view的frame 5.设置最热评论view的frame
    */
    
    //热门评论
    if (vm.item.commentItem) {
        self.hotView.hidden = NO;
        self.hotView.commentItem = vm.item.commentItem;
        self.hotView.frame = vm.hotViewFrame;
    }else{
        self.hotView.hidden = YES;
    }
    
    //底部点赞
    self.bottomView.frame = vm.bottomViewFrame;
    self.bottomView.item = vm.item;
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    }

@end
